package com.bobo.web.provider.controller.api;

import com.bobo.web.api.domain.video.CommentDO;
import com.bobo.web.api.domain.video.VideoInfoDTO;
import com.bobo.web.api.domain.video.VideoTokenDto;
import com.bobo.web.api.vo.PictureVO;
import com.bobo.web.api.vo.base.ResponseResult;
import com.bobo.web.provider.service.VideoAndPictureService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("api/video")
public class VideoAndPictureController {
    @Resource
    private VideoAndPictureService videoAndPictureService;

    /**
     * 获取上传凭证
     *
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/getQiNiuUploadToken", method = {RequestMethod.GET})
    public ResponseResult<VideoTokenDto> getQiNiuUploadToken() throws Exception {
        ResponseResult<VideoTokenDto> result = videoAndPictureService.getToken();
        return result;
    }
    /**
     * 保存图片地址
     *
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/savePicture", method = {RequestMethod.POST})
    public ResponseResult<String> savePicture(@RequestBody PictureVO pictureVO) throws Exception {
        if(StringUtils.isBlank(pictureVO.getGameId())||StringUtils.isBlank(pictureVO.getPicUrl())){
            ResponseResult.error("参数不全");
        }
        ResponseResult<String> result = videoAndPictureService.savePicture(pictureVO);
        return result;
    }
    /**
     * 保存视频信息，并转码
     *
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/saveVideoAndTranscoding", method = {RequestMethod.POST})
    public ResponseResult<String> saveVideoAndTranscoding(@RequestBody VideoInfoDTO videoInfoDTO) throws Exception {
        ResponseResult<String> result = videoAndPictureService.transcoding(videoInfoDTO);
        return result;
    }
    /**
     * 点赞接口
     *
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/addFabulous", method = {RequestMethod.POST})
    public ResponseResult<String> addFabulous(@RequestBody VideoInfoDTO videoInfoDTO) throws Exception {
        videoAndPictureService.addFabulous(videoInfoDTO);
        return ResponseResult.success();
    }
    /**
     * 点赞接口
     *
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "/addComment", method = {RequestMethod.POST})
    public ResponseResult<String> addComment(@RequestBody CommentDO commentDO) throws Exception {
        videoAndPictureService.addComment(commentDO);
        return ResponseResult.success();
    }
}
